<template>
  <div class="dashboard">
    <part-head></part-head>
    <div class="body">
      <div class="left">
        <part-left :data="stadium_data"></part-left>
      </div>
      <div class="right">
        <part-notice></part-notice>
        <part-carousel
          :ageData="age_data"
          :genderData="gender_data"
          :monthData="month_data"
        ></part-carousel>
      </div>
    </div>
  </div>
</template>

<script>
import partHead from "@/dashboard/components/head";
import partLeft from "./part-left";
import partNotice from "./part-notice";
import partCarousel from "./part-carousel";

import { stDashboardData } from "@/api/dashboard";

export default {
  components: {
    partCarousel,
    partLeft,
    partHead,
    partNotice
  },
  data() {
    return {
      loading: true,

      age_data: {},
      gender_data: {},
      month_data: {},
      stadium_data: {}
    };
  },
  mounted() {
    this.get_data();

    setInterval(() => {
      if (this.loading) return;
      this.get_data();
    }, 5000);
  },
  methods: {
    get_data() {
      this.loading = true;

      stDashboardData()
        .then(r => {
          this.loading = false;
          if (r.code == 200) {
            this.age_data = r.data.age_data;
            this.gender_data = r.data.gender_data;
            this.month_data = r.data.month_data;
            this.stadium_data = r.data.stadium_data;
          }
        })
        .catch(err => {
          this.loading = false;
        });
    }
  }
};
</script>

<style lang="scss" scoped>
.dashboard {
  background: #1f2327;
  min-height: 100vh;
  width: 100vw;
  padding: 0 40px 40px;
  color: #fff;
  .body {
    width: 100%;
    display: flex;
    justify-content: space-between;
    .left {
      width: 480px;
    }
    .right {
      width: 1330px;
    }
  }
}
</style>
